package vip.youngboy.longpoll.security;

import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;
import vip.youngboy.longpoll.config.AuthoritiesConstants;

/**
 * Authenticate a user from the database.
 */
@Component("userDetailsService")
public class DomainUserDetailsService implements UserDetailsService {

    private final Logger log = LoggerFactory.getLogger(DomainUserDetailsService.class);


    @Override
    public UserDetails loadUserByUsername(final String login) {
        User user = new User("youngboy", new BCryptPasswordEncoder().encode("123456"), Lists.newArrayList(newAuthority(AuthoritiesConstants.ADMIN)));
        return user;
    }

    private SimpleGrantedAuthority newAuthority(String authority) {
        return new SimpleGrantedAuthority(authority);
    }

}
